React에서 만든 별점 표시기

✒️ 2025-05-16 12:35 내용 수정


import { StarFill } from "react-bootstrap-icons";

function starRating(rate) {

    const totalStar = 5; // 전체 별 개수
    const yellowStar = rate; // 평점 별 개수
    const grayStar = totalStar - yellowStar; // 빈 별 개수

    const yellowStars = Array.from({length:yellowStar}, (_, index) => (
        <StarFill key={index} style={{color: '#FFC100'}}></StarFill>
    ));
    const grayStars = Array.from({length:grayStar}, (_, index) => (
        <StarFill key={index} style={{color: '#bebdbd'}}></StarFill>
    ));

    return (
        <div>
            {yellowStars}
            {grayStars}
        </div>
    )
}

export default starRating;

star 1.png star 2.png